package com.jiuzhou.guanwang.jzcp.base;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.jiuzhou.guanwang.jzcp.BaseApplication;
import com.jiuzhou.guanwang.jzcp.utils.AppStatusManager;
import com.jiuzhou.guanwang.jzcp.widget.LoadingProgressDialog;

import butterknife.ButterKnife;

/**
 * Created by isfaaghyth on 6/17/17.
 */

public abstract class BaseActivity<P extends BasePresenter> extends AppCompatActivity {
    protected Context mContext;
    protected BaseApplication applica;
    protected P presenter;
    protected LoadingProgressDialog progressDialog;

    protected abstract P initPresenter();

    protected abstract void initialize();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
//        if (checkAppStatus()) {
//            Intent intent = new Intent(this, MainActivity.class);
//            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
//            startActivity(intent);
//            finish();
//        }

        super.onCreate(savedInstanceState);

//        if (Build.VERSION.SDK_INT >= 19) {
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            if (Build.VERSION.SDK_INT >= 21) {
//                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
//                getWindow().addFlags(Integer.MIN_VALUE);
//                getWindow().setStatusBarColor(Color.TRANSPARENT);
//            }
//        }
    }
    private boolean checkAppStatus() {
        if (AppStatusManager.getInstance().getAppStatus() == AppStatusManager.AppStatusConstant.APP_FORCE_KILLED) {
            //该应用已被回收，执行相关操作（下面有详解）
            return true;
        } else {
            return false;
        }
    }
    protected void binding(int layoutId) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        getWindow().setSoftInputMode(
//                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(layoutId);
        mContext = this;
        applica = BaseApplication.getInstance();
        ButterKnife.bind(this);
        presenter = initPresenter();
        initialize();
    }
    public LoadingProgressDialog getLoadingProgressDialog() {
        if (null == progressDialog) {
            progressDialog = new LoadingProgressDialog(this, "加载中...");
            progressDialog.setCancelable(true);
            progressDialog.setCanceledOnTouchOutside(false);
        }
        return progressDialog;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) presenter.dettachView();
    }

    public void showToast(String text) {
        Toast.makeText(this, "" + text, Toast.LENGTH_SHORT).show();
    }

    public void showToast(int resId) {
        Toast.makeText(this, this.getResources().getText(resId), Toast.LENGTH_SHORT).show();
    }


    public void showDialog(String title, String messsage, String positiveMsg, View.OnClickListener okListener, String negative,
                           View.OnClickListener cancleListener) {

//        AlertDialog dialog = new AlertDialog(mContext).builder();
//        if (!TextUtils.isEmpty(title)) {
//            dialog.setTitle(title);
//        }
//        if (!TextUtils.isEmpty(messsage)) {
//            dialog.setMsg(messsage);
//        }
//        dialog.setPositiveButton(positiveMsg, okListener).setNegativeButton(negative, cancleListener);
//
//        dialog.show();
    }
//    @Override
//    protected void onResume() {
//        super.onResume();
//        MobclickAgent.onResume(this);
//    }
//
//    @Override
//    protected void onPause() {
//        super.onPause();
//        MobclickAgent.onPause(this);
//    }

    public void back(View targv) {
        finish();
    }

}
